package com.kehao.leetcode.basic.others;

import org.junit.Test;

public class MissingNumberSolution {
    public int missingNumber(int[] nums) {
//        boolean[] answerArray = new boolean[nums.length+1];
//        for (int i = 0; i < nums.length; i++) {
//            answerArray[nums[i]] = true;
//        }
//        for (int i = 0; i < answerArray.length; i++) {
//            if(answerArray[i]!=true) return i;
//        }
//        return 0;
        int result = 0;
        for (int i = 0; i < nums.length; i++) {
            result = result^i^nums[i];
        }
        result=result^ (nums.length);
        return result;
    }

    @Test
    public void test01(){
       int[] nums = {9,6,4,2,3,5,7,0,1};
        System.out.println(missingNumber(nums));
    }
}
